﻿using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Linq;
using System.Reflection;
using System.Threading.Tasks;
using System.Windows.Forms;

namespace CloudApiServer
{
    internal static class Program
    {
        /// <summary>
        /// 应用程序的主入口点。
        /// </summary>
        [STAThread]
        static void Main()
        {
            Application.EnableVisualStyles();
            SystemInfo.Version = Assembly.GetExecutingAssembly().GetName().Version.ToString();
            string[] parts = SystemInfo.Version.Split('.');
            if (parts.Length >= 4)
            {
                if (int.TryParse(parts[2], out int days))
                {
                    DateTime baseDate = new DateTime(2000, 1, 1);
                    DateTime dateWithDays = baseDate.AddDays(days);
                    SystemInfo.Versiontime = dateWithDays.ToString("yyyy-MM-dd");
                }
                else
                {
                    SystemInfo.Versiontime = "天数部分无法转换为整数";
                }
            }
            else
            {
                SystemInfo.Versiontime = "版本号格式不正确，无法找到天数部分";
            }
            Process[] myProcesses = Process.GetProcessesByName("CloudApiServer");//获取指定的进程名
            if (myProcesses.Length > 1) //如果可以获取到知道的进程名则说明已经启动
            {
                DialogResult resault = MessageBox.Show("程序已启动,是否需要强制退出已开启程序?", "提示", MessageBoxButtons.OKCancel, MessageBoxIcon.Asterisk);
                if (resault == DialogResult.OK)
                {
                    foreach (System.Diagnostics.Process p in myProcesses)
                    {
                        p.Kill();
                    }
                }
                else
                {
                    Application.Exit();
                    return;
                }
            }
            Application.SetCompatibleTextRenderingDefault(false);
            Application.Run(new MainFrom());
        }
    }
}
